/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package blink.guimodel;

import blink.model.Target;
import blink.model.Task;
import javax.swing.AbstractListModel;
import javax.swing.ListModel;
import javax.swing.event.ListDataListener;

/**
 *
 * @author jerome
 */
public class TargetListModel extends AbstractListModel{

    
    private Task task;
    
    public TargetListModel(Task t) {
        task=t;
    }
    
    @Override
    public int getSize() {
        return task.getTargets().size();
    }

    @Override
    public Object getElementAt(int i) {
        return task.getTargets().get(i);
    }
    
    public void createNewTarget() {
        int size = getSize();
        new Target("Target "+size,task);
        this.fireIntervalAdded(this, size, size);
        
    }
    
    public void remove(int idx) {
        task.removeTarget(task.getTargets().get(idx));
        this.fireIntervalRemoved(this, idx, idx);
        
    }

    public void fireContentsChanged(int selectedIndex) {
        fireContentsChanged(this,selectedIndex,selectedIndex);
    }


    
}
